package cn.bgs.service.impl;

import cn.bgs.common.R;
import cn.bgs.pageUtil.MybatisPageHelper;
import cn.bgs.pageUtil.PageResult;
import cn.bgs.pojo.TemporaryCarPark;
import cn.bgs.mapper.TemporaryCarParkMapper;
import cn.bgs.service.ITemporaryCarParkService;
import cn.bgs.vo.RecordVo;
import cn.bgs.vo.AreaVo;
import cn.bgs.vo.CommunityVo;
import cn.bgs.vo.TemporVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

import java.util.List;

/**
 * <p>
 * 停车缴费表 服务实现类
 * </p>
 *
 * @author cf
 * @since 2022-06-07
 */
@Service
public class TemporaryCarParkServiceImpl extends ServiceImpl<TemporaryCarParkMapper, TemporaryCarPark> implements ITemporaryCarParkService {
    @Autowired
    TemporaryCarParkMapper temporaryCarParkMapper;
    @Override
    public R selectParkInfo(TemporVo temporVo) {
        MybatisPageHelper.startPage(temporVo.getPageRequest());
        PageResult pageResult = MybatisPageHelper.getPageResult(temporaryCarParkMapper.selectParkInfo(temporVo));
        return R.ok().data("data",pageResult);
    }

    @Override
    public boolean updateParkInfo(TemporVo temporVo) {
        int i = temporaryCarParkMapper.updateParkInfo(temporVo);
        if (i>0){
            return true;
        }
        return false;
    }

    @Override
    public void appvehicleUpdate(RecordVo recordVo) {
        LocalDateTime localDateTime = LocalDateTime.now();
        temporaryCarParkMapper.updateCarPark(recordVo.getTemporaryCarParkId());

        recordVo.setPrepaidNumber("232323");
        recordVo.setPaymentTypeId(recordVo.getTemporaryCarParkId());
        recordVo.setTopUpTime(localDateTime);
        recordVo.setPaymentAmount(recordVo.getPayFees());
        recordVo.setState(1);
        recordVo.setMethodOfPayment("微信支付");
        recordVo.setCreateTime(localDateTime);
        recordVo.setUpdateTime(localDateTime);
        recordVo.setDeleteFlag("n");
        temporaryCarParkMapper.insertTopUp(recordVo);


    }
    @Override
    public boolean aedParkInfo(TemporVo temporVo) {
        boolean a = temporaryCarParkMapper.aedParkInfo(temporVo);
        return a;
    }

    @Override
    public R deleteParkInfo(Integer temporaryCarParkId) {
        int deleteP = temporaryCarParkMapper.deleteParkInfo(temporaryCarParkId);
        return R.ok().data("deleteP", deleteP);
    }

    @Override
    public R info(CommunityVo communityVo) {
        List<AreaVo> list = temporaryCarParkMapper.info(communityVo);
        return R.ok().data("data",list);
    }
}
